package pack0812;


public class Work6 {
        //6：输入数组，返回数组中重复最多和重复最少的元素
        public static void main(String[] args) {
            int[] array = {2,5,3,2,5,8,1,2,4,};
            int[] newArr = new int[array.length];
            //判断相等的元素并计数
            for(int i = 0; i<array.length; i++){
                int sum = 0;
                for(int j = 0; j<array.length; j++){
                    if(array[i]==array[j]){
                        sum++;
                    }
                }
                newArr[i] = sum;
            }
            //排序
            for (int i = 0; i<newArr.length-1; i++){
                for(int j = 0; j<newArr.length-1-i; j++){
                    if(newArr[j]>newArr[j+1]){
                        int a = newArr[j];
                        newArr[j] = newArr[j+1];
                        newArr[j+1] = a;
                    }
                }
            }
            /*for(int i = 0; i<newArr.length; i++){
                System.out.print(newArr[i]+"\t");
            }*/
            //
            for(int i = 0; i<array.length; i++){
                int sum = 0;
                for(int j = 0; j<array.length; j++){
                    if(array[i]==array[j]){
                        sum++;
                    }
                }
                if(sum==newArr[newArr.length-1]){
                    System.out.println("重复最多的元素"+array[i]);
                }else if(sum == newArr[0]){
                    System.out.println("重复最少的元素"+array[i]);
                }
            }

        }
}
